/**
 * Created by Administrator on 2016/12/16.
 */
window.onload = function(){
    var menuleft = document.querySelector('.menu_b_left')
    var leftheight = menuleft.offsetHeight;
    var leftul = menuleft.querySelector('ul');
    console.log(leftul);
    var leftulheight = leftul.offsetHeight;
    console.log(leftulheight);
    var maxposition = 0;
    var minposition = leftheight-leftulheight;
    console.log(minposition);
    var maxbaoposition = maxposition+100;
    var minbaoposition = minposition-100;
    var currentY = 0;
    var startY = 0;
    var moveY = 0;
    var distancyY = 0;
    function closeTransition(){
        leftul.style.transition = 'none';
        leftul.style.webkittransition = 'none';
    }
    function openTransition(){
        leftul.style.transition = 'all .2s';
        leftul.style.webkittransition = 'all .2s';
    }
    function settransform(distancyY){
        //leftul.style.transform = 'translateY(' + (distanceY) + 'px)';
        //leftul.style.webkittransform = 'translateY(' + (distanceY) + 'px)';
        leftul.style.transform = 'translateY('+(distancyY)+'px)';
        leftul.style.webkitTransform = 'translateY('+(distancyY)+'px)';
    }
    leftul.addEventListener('touchstart',function(e){
        startY = e.touches[0].clientY;
        //console.log(startY);
    })
    leftul.addEventListener('touchmove',function(e){
        moveY = e.touches[0].clientY;
        distancyY = moveY-startY;

        if(currentY+distancyY>maxbaoposition||currentY+distancyY<minbaoposition){
            return;
        }
        closeTransition();
        settransform(currentY+distancyY);
    })
    leftul.addEventListener('touchend',function(){
        //console.log(0222);
        if(currentY+distancyY>maxposition){
            currentY = maxposition;
            openTransition();
            settransform(maxposition);
            console.log(currentY);
        }else if(currentY+distancyY<minposition){
            currentY = minposition;
            openTransition();
            settransform(minposition);
            console.log(currentY);
        }
        else{
            currentY+=distancyY;
            //console.log(currentY);
        }
    })
}
